package com.hjh.java.rabbitmq.service.simple;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Slf4j
@Component
public class HelloSender1 {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send() {
        String sendMsg = "hello1 " + new Date();
        log.info("==========>sendMsg:{}",sendMsg);

        //第一个参数是routingKey(没有指定exchange时,routingKey直接对应队列名称)
        //第二个参数是发送的数据
        this.rabbitTemplate.convertAndSend("hello", sendMsg);
    }


    public void send2() {
        String sendMsg = "hello1 " + new Date();
        log.info("==========>sendMsg:{}",sendMsg);

        //第一个参数是routingKey(没有指定exchange时,routingKey直接对应队列名称)
        //第二个参数是发送的数据
        this.rabbitTemplate.convertAndSend("queue.name.import", sendMsg);
    }
}
 
  